package archer.framework.protocol.result;

import archer.framework.utils.ValidateUtils;
import jodd.json.meta.JSON;

import java.util.ArrayList;
import java.util.List;

/**
 * 执行结果包装类，主要用来处理返回json忽略某些字段
 *
 * @author christ
 * @date 2015/8/31
 */
public class ExecuteResultWrapper extends ExecuteResult {

    /**
     * 需要序列化的字段集合
     */
    @JSON(include = false)
    private List<String> includes = new ArrayList<String>();

    /**
     * 需要忽略的字段集合
     */
    @JSON(include = false)
    private List<String> excludes = new ArrayList<String>();

    /**
     * 被包装的结果类
     */
    private ExecuteResult executeResult;


    public ExecuteResultWrapper(ExecuteResult executeResult) {
        super(executeResult);
        this.executeResult = executeResult;
    }

    //-----------------------------api-------------------------------

    /**
     * 需要序列化的字段
     *
     * @param fields
     * @return
     */
    public ExecuteResultWrapper include(String... fields) {

        if (ValidateUtils.isNotEmpty(fields)) {
            for (String each : fields) {
                this.includes.add("resultData." + each);
            }
        }
        return this;
    }

    /**
     * 需要忽略的字段
     *
     * @param fields
     * @return
     */
    public ExecuteResultWrapper exclude(String... fields) {

        if (ValidateUtils.isNotEmpty(fields)) {
            for (String each : fields) {
                this.excludes.add("resultData." + each);
            }
        }
        return this;
    }


    //-----------------------------inner-------------------------------

    public List<String> getIncludes() {
        return includes;
    }

    public ExecuteResultWrapper setIncludes(List<String> includes) {
        this.includes = includes;
        return this;
    }

    public List<String> getExcludes() {
        return excludes;
    }

    public ExecuteResultWrapper setExcludes(List<String> excludes) {
        this.excludes = excludes;
        return this;
    }

    public ExecuteResult getExecuteResult() {
        return executeResult;
    }

    public ExecuteResultWrapper setExecuteResult(ExecuteResult executeResult) {
        this.executeResult = executeResult;
        return this;
    }

}
